package cn.yudao.ymcc.mq.consumer;


import cn.yudao.ymcc.dto.Order2PayTranMesDto;
import cn.yudao.ymcc.service.IPayOrderService;
import com.alibaba.fastjson.JSONObject;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.File;

@Component
@RocketMQMessageListener(consumerGroup="service-pay-consumer",
        topic="topic-order",
        selectorExpression="tags-order",
        messageModel = MessageModel.CLUSTERING) // 默认是集群 1个消息被一个消费者消费 MessageModel.BROADCASTING 广播 1个消息被所有的消费者消费
public class Order2PayConsumer implements RocketMQListener<MessageExt> {


    @Autowired
    private IPayOrderService payOrderService;


    @Override
    public void onMessage(MessageExt message) {

        byte[] body = message.getBody();
        Order2PayTranMesDto mediaFile = JSONObject.parseObject(body, Order2PayTranMesDto.class);
        // 调用方法执行业务 -- 不报错会自动完成签名
        payOrderService.savePayOrderByOrder(mediaFile);
    }
}
